package com.lsz.intelligentflowerwatering.ui

import android.content.Intent
import android.net.Uri
import android.widget.Toast
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.lsz.intelligentflowerwatering.viewmodel.TestViewModel

@Composable
fun Setting(
    testViewModel: TestViewModel = viewModel(),
    jumpToFront: () -> Unit
) {

    val context = LocalContext.current
    Column(
        Modifier
            .padding(30.dp)
            .fillMaxWidth()
            .fillMaxHeight()
    ) {
        TheText(text = "请等待，此过程可能需要一段时间")
        LazyColumn(
            modifier = Modifier
                .fillMaxWidth()
                .weight(4f)
                .padding(30.dp),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            itemsIndexed(testViewModel.setList) { index, item ->
                TheSettingItem(testViewModel.statusList[index], item)
            }
        }

        Row(
            modifier = Modifier
                .weight(1f)
                .fillMaxWidth(),
            horizontalArrangement = Arrangement.Center
        ) {
//            TheButton("设备重命名", onClick = { })
            TheButton("完成", onClick = {
                if (testViewModel.statusList.contains(false)) {
                    Toast.makeText(
                        context,
                        "请稍等，正在配置中\\n配置成功后，点击完成会自动跳转到客户端",
                        Toast.LENGTH_LONG
                    ).show()
                } else {
                    jumpToFront
                }
            })
        }
    }

}